<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>宇成建筑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../statics/css/font.css">
    <link rel="stylesheet" href="../statics/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="../statics/css/xadmin.css">
    <link rel="stylesheet" href="../statics/css/style.css">
    <style>
        .layui-table td, .layui-table th {
            min-width: 40px;
        }
    </style>
</head>

<body class='labelAuto'>
<div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="welcome.html">首页</a>
            <a href="javascript:;">施工管理</a>
            <a href="javascript:;" class="lv1">杂工分账汇总</a>
            <a href="javascript:;" class="lv2"></a>
            <a class="lv3">
                <cite></cite>
            </a>
        </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right:10px"
       onclick="window.history.go(-1)" title="后退">
        <i class="iconfontBlod" style="line-height:30px">&#xe74f;</i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
<!--                <div class="layui-card-body search">-->
<!--                    <form action="" class="layui-form livingList">-->
<!--                        <div class="layui-form-item">-->
<!--                            <div class="layui-inline">-->
<!--                                <label class="layui-form-label">搜索</label>-->
<!--                                <div class="layui-input-block">-->
<!--                                    <input type="search" autocomplete="off" class="layui-input">-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="layui-inline">-->
<!--                                <button class="layui-btn search" type="button" id='search'>-->
<!--                                    <i class="iconfont layui-icon">&#xe615;</i>-->
<!--                                </button>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </form>-->
<!--                </div>-->
                <div class="layui-card-body tableCardBody">
                    <table class="layui-table" id="lists" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="../statics/plugins/layui/layui.js" charset="utf-8"></script>
<script src='../statics/plugins/jQuery-3.2.1/jquery-3.2.1.min.js'></script>
<script type="text/javascript" src="../statics/plugins/X-admin/xadmin.js"></script>
<script type="text/javascript" src="../statics/js/public.js?v=1129"></script>
<script type="text/javascript">
    layui.use(['form', 'layer', "table", "laydate"], function () {
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var layer = layui.layer;
        var projectId = getQueryString('projectId');
        var sectionId = getQueryString('sectionId');
        var areaId = getQueryString('areaId');
        $('a.lv2').html(localStorage.getItem('areaName'));
        $('a.lv3 cite').html(localStorage.getItem('sectionName'));
        // 异步数据加载
        var lists = table.render({
            elem: '#lists', //绑定DOM元素
            id: 'lists', //table的id
            title: '人员列表',
            height: 'full-150',
            contentType: "application/json; charset=utf-8",
            url: url + '/project/project/handymanAccountsLists', //数据接口地址
            request: {
                pageName: 'page', //页码的参数名称，默认：page
                limitName: 'length' //每页数据量的参数名，默认：limit
            },
            parseData: function (res) {
                return {
                    "code": res.code, //解析接口状态
                    "data": res.data.data,
                    "msg": res.msg,
                    "count": res.data.count
                };
            },
            method: 'POST',
            where: {
                projectId: projectId,
                sectionId: sectionId,
                search: "",
                token: getToken()
            },
            toolbar: '#toolbar',
            defaultToolbar: ['filter',{title: '导出', layEvent: 'excel', icon: 'layui-icon-export'}],
            page: true, //开启分页
            limit: 10, //默认每页记录条数
            limits: [10, 20, 50], //每页记录条数可选数量
            cols: [
                [ //表头
                    {field: '', title: '编号', type: 'numbers', width: '4%'},
                    {field: 'jobNumber', title: '工号', width: '5%'},
                    {field: 'employeeName', title: '工人', width: '6%'},
                    // {field: 'projectName', title: '项目', width: '10%'},
                    {
                        field: 'areaName', title: '作业区域', width: '15%', templet: function (d) {
                            return html = `<span class='table_inp' title=${d.areaName + '、' + d.sectionName}>${d.areaName + '、' + d.sectionName}</span>`
                        }
                    },
                    {field: 'professionName', title: '作业工种', width: '8%'},
                    {field: 'assignmentName', title: '施工项', width: '10%'},
                    {field: 'assignmentDetail', title: '具体明细', width: '22%'},
                    {field: 'account', title: '分账金额', width: '8%',templet:function(d){return numberFormat(d.account,'currency')}},
                    {
                        field: 'separateTime', title: '记账时间', width: "8%", templet: function (d) {
                            return (d.separateTime).substr(0, 10);
                        }
                    },
                    {field: 'adminName', title: '录入人', width: '6%'},
                    {
                        field: 'status', title: '审核状态', width: '8%', templet: function (d) {
                            if (d.status == 1){
                                return '已保存，待提交';
                            }else if (d.status == 2){
                                return '待审核';
                            }else if (d.status == 3){
                                return '审核通过';
                            }else if (d.status == 4){
                                return '审核不通过';
                            }else{
                                return '-';
                            }
                        }
                    },
                ]
            ],
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 100000, //成功的状态码，默认：0
                msgName: 'msg', //状态信息的字段名称，默认：msg
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'data' //数据列表的字段名称，默认：data
            }
        });
        table.on('tool(test)', function (data) {

        });
        table.on('toolbar(test)', function (data) {
            if (data.event == 'excel') {
                layer.open({
                    type: 0,
                    title: "杂工分账",
                    area: ["40%", '60%'],
                    content: `
                            <form class="layui-form layerOpen" action="">
                                <div class="layui-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">分账周期</label>
                                        <div class="layui-input-inline" style="width:150px;">
                                            <input type="text" class="layui-input" id="startTime" autocomplete="off">
                                        </div>
                                        -
                                        <div class="layui-input-inline" style="width:150px;">
                                            <input type="text" class="layui-input" id="endTime" autocomplete="off">
                                        </div>
                                    </div>
                                </div>
                            </form>
                        `,
                    btn: ['确定','关闭'],
                    skin: 'my-skin',
                    success: function () {
                        laydate.render({
                            elem: '#startTime' //指定元素
                        });
                        laydate.render({
                            elem: '#endTime' //指定元素
                        });
                    },
                    yes: function () {
                        var startTime = $('input#startTime').val();
                        var endTime = $('input#endTime').val();
                        if (startTime == ''){
                            layer.open({
                                type: 0,
                                title: "杂工分账",
                                area: ["40%", '30%'],
                                content: `请选择导出起始时间`,
                                btn: ['关闭'],
                                skin: 'my-skin'
                            })
                            return false;
                        }
                        if (endTime == ''){
                            layer.open({
                                type: 0,
                                title: "杂工分账",
                                area: ["40%", '30%'],
                                content: `请选择导出截止时间`,
                                btn: ['关闭'],
                                skin: 'my-skin'
                            })
                            return false;
                        }
                        var s = new Date(startTime);
                        var e = new Date(endTime);
                        if(e>s){
                            layer.open({
                                type: 0,
                                title: "杂工分账",
                                area: ["40%", '30%'],
                                content: `请选择截止时间不能小于起始时间`,
                                btn: ['关闭'],
                                skin: 'my-skin'
                            })
                        }
                        layer.closeAll();
                        layer.open({
                            type: 0,
                            title: "杂工分账",
                            area: ["40%", '30%'],
                            content: `当前杂工分账记录正在生成中,请稍等!`,
                            btn: ['关闭'],
                            skin: 'my-skin'
                        });
                        $.ajax({
                            url: url + '/excel/export/handymanAccounts',
                            type: 'post',
                            data: {
                                projectId:getParam('projectId'),
                                startTime:startTime,
                                endTime:endTime,
                                token: getParam('token')
                            },
                            success: function (r) {
                                if (r.code == 100000) {
                                    layer.closeAll();
                                    layer.open({
                                        type: 0,
                                        title: "导出",
                                        area: ["40%", '30%'],
                                        content: `<p class='one_p'>${r.msg}</p>`,
                                        btn: ['关闭'],
                                        skin: 'my-skin'
                                    })
                                } else {
                                    layer.closeAll();
                                    layer.open({
                                        type: 0,
                                        title: "导出",
                                        area: ["40%", '30%'],
                                        content: `<p class='one_p'>${r.msg}</p>`,
                                        btn: ['关闭'],
                                        skin: 'my-skin'
                                    })
                                }
                            }
                        })
                    }
                });
            }
        });
        // $('body').on('click', '#search', function () {
        //     var search = $(this).parent().prev().find('input').val();
        //     table.reload('lists', {
        //         page: {
        //             curr: 1 //重新从第 1 页开始
        //         },
        //         where: {
        //             "search": search
        //         }
        //     })
        // })

        $('body').on('click','button.add',function(){
            window.location.href = 'addHandymanAccounts.html'
        });

        $('a.lv1').on('click',function(){
            window.location.href=`handymanAccountsSummary.html`;
        });

        $('a.lv2').on('click',function(){
            window.location.href=`constructionLedgerZaGong.html?areaId=${areaId}&projectId=${projectId}`;
        })

    });
</script>

</html>